package com.ds.lens.data.service.dao;

import com.github.pagehelper.Page;
import com.ds.lens.data.service.dao.entity.LensIntegration;
import com.ds.lens.data.service.dao.sql.provider.LensIntegrationSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * Description:
 *
 * @author WeiShaoying
 * @date 2019-11-04
 */
@Repository
public interface LensIntegrationDao {

    String COLUMNS = "id, name, type, icon, url, description, creator, created_time, mender, modified_time ";

    @Delete({
            "delete from lens_integration",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into lens_integration (",
            COLUMNS,
            ") values (#{id,jdbcType=BIGINT}, ",
            "#{name,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, ",
            "#{icon,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, ",
            "#{description,jdbcType=VARCHAR}, #{creator,jdbcType=VARCHAR}, ",
            "#{createdTime,jdbcType=TIMESTAMP}, #{modifiedTime,jdbcType=TIMESTAMP})"
    })
    int insert(LensIntegration record);

    @InsertProvider(type = LensIntegrationSqlProvider.class, method = "insertSelective")
    int insertSelective(LensIntegration record);

    @Select({
            "select",
            COLUMNS,
            "from lens_integration",
            "where id = #{id,jdbcType=BIGINT}"
    })
    @Results(id = "lensIntegration", value = {
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "type", property = "type", jdbcType = JdbcType.INTEGER),
            @Result(column = "icon", property = "icon", jdbcType = JdbcType.VARCHAR),
            @Result(column = "url", property = "url", jdbcType = JdbcType.VARCHAR),
            @Result(column = "description", property = "description", jdbcType = JdbcType.VARCHAR),
            @Result(column = "creator", property = "creator", jdbcType = JdbcType.VARCHAR),
            @Result(column = "created_time", property = "createdTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "mender", property = "mender", jdbcType = JdbcType.VARCHAR),
            @Result(column = "modified_time", property = "modifiedTime", jdbcType = JdbcType.TIMESTAMP)
    })
    LensIntegration selectByPrimaryKey(Long id);

    @UpdateProvider(type = LensIntegrationSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(LensIntegration record);

    @Update({
            "update lens_integration",
            "set name = #{name,jdbcType=VARCHAR},",
            "type = #{type,jdbcType=INTEGER},",
            "icon = #{icon,jdbcType=VARCHAR},",
            "url = #{url,jdbcType=VARCHAR},",
            "description = #{description,jdbcType=VARCHAR},",
            "creator = #{creator,jdbcType=VARCHAR},",
            "created_time = #{createdTime,jdbcType=TIMESTAMP},",
            "mender = #{mender,jdbcType=VARCHAR},",
            "modified_time = #{modifiedTime,jdbcType=TIMESTAMP}",
            "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(LensIntegration record);

    @Select({
            "select",
            COLUMNS,
            "from lens_integration"
    })
    @ResultMap("lensIntegration")
    Page<LensIntegration> queryLensIntegration();

    @Select({
            "select",
            COLUMNS,
            "from lens_integration where type in (1,3)"
    })
    @ResultMap("lensIntegration")
    List<LensIntegration> queryLensIntegrationMenu();

    /**
     * @param name
     * @return
     */
    @Select({
            "select",
            COLUMNS,
            "from lens_integration where name = #{name}"
    })
    @ResultMap("lensIntegration")
    LensIntegration selectByName(String name);
}
